{include file="public/nheader"}
<div class="layui-fluid">
    <div class="layui-card">
        <!-- // 默认操作按钮 -->
        <div class="layui-card-header layadmin-card-header-auto ">
            <div class="layui-form">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <select name="status" lay-verify="">
                                <option value="">状态</option>
                                <option value="1" {if !empty(input('get.status')) &&
                                    input('get.status')==1}selected{/if}>待使用</option>
                                <option value="2" {if !empty(input('get.status')) &&
                                    input('get.status')==2}selected{/if}>已使用</option>
                                <option value="2" {if !empty(input('get.status')) &&
                                    input('get.status')==2}selected{/if}>已作废</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <input name="title" class="layui-input" type="text" placeholder="ID搜索" />
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <input name="code" class="layui-input" type="text" placeholder="兑换码搜索" />
                        </div>
                    </div>
                    <input type="hidden" name="promoid" value="{:input('promoid/d',0)}" />
                    <div class="layui-inline">
                        <!-- // 默认搜索 -->
                        <button class="layui-btn icon-btn" lay-filter="formSearch" lay-submit>搜索</button>
                        <!-- // 删除所有 -->
                        <button class="layui-btn icon-btn layui-btn-danger" lay-batch="lay-tableList"
                            data-url="/agent/keys_status">批量作废
                        </button>
                    </div>
                </div>
            </div>
        </div>
        <!-- // 创建数据实例 -->
        <table id="lay-tableList" lay-filter="lay-tableList"></table>
    </div>
</div>

<!-- // 列表工具栏 -->
<script type="text/html" id="tableBar">
    {{#  if(d.status ==1){ }}
    <a class="layui-table-text" style="color:#FF5722" data-url="/agent/keys_status?id={{d.id}}&status=3" data-reload="self" data-confirm="" lay-ajax="">作废兑换码</a>
    {{# }if(d.status ==2) { }}
        <a class="layui-table-text" lay-open data-title="领取详情" data-area="80%,90%" data-url="/user/coupon?keyid={{d.id}}" >领取详情</a>
    {{# }if(d.status ==3) { }}
        已作废
    {{#  } }}
</script>

{include file="public/nfooter"}
<script>
    layui.use(['admin', 'layer', 'table', 'form'], function () {
        var admin = layui.admin;
        var layer = layui.layer;
        var table = layui.table;        // 表格
        var form = layui.form;
        /*
    * 初始化表格
   */
        var isTable = table.render({
            elem: "#lay-tableList"
            , url: "{:url()}"
            , page: true
            , size: 'lg'
            , even: true
            , where: {
                promoid: "{:input('promoid/d',0)}"
            }
            , toolbar: '#toolbarDemo'
            , defaultToolbar: [{
                title: '导出excel,如需全部导出数据请将底部数据选择100000/页' //标题
                , layEvent: 'LAYTABLE_EXPORT' //事件名，用于 toolbar 事件中使用
                , icon: 'layui-icon-export' //图标类名
            }, {
                title: '打印页面' //标题
                , layEvent: 'LAYTABLE_PRINT' //事件名，用于 toolbar 事件中使用
                , icon: 'layui-icon-print' //图标类名
            }, {
                title: '筛选数据' //标题
                , layEvent: 'LAYTABLE_COLS' //事件名，用于 toolbar 事件中使用
                , icon: 'layui-icon-cols' //图标类名
            }], limits: [15, 100, 500, 1000, 5000, 10000, 50000, 100000]
            , limit: 15
            , cols: [[
                { type: 'checkbox', width: 60 },
                { field: 'id', align: 'center', sort: true, width: 80, title: 'ID' },
                { field: 'agent_name', width: 200, align: 'center', title: '持码代理' },
                { field: 'code', width: 150, align: 'center', title: '兑换码' },
                { field: 'btmoney', width: 100, align: 'center', title: '已兑换券总额' },
                { field: 'btmoney1', width: 100, align: 'center', title: '已兑换待使用总额' },
                {
                    field: 'status', align: 'center', width: 120, templet: function (d) {
                        if (d.status == 1) {
                            return '待使用';
                        }
                        if (d.status == 2) {
                            return '已使用';
                        }
                        if (d.status == 3) {
                            return '已作废';
                        }
                        return '结束';
                    }, title: '状态'
                },
                { field: 'created', width: 200, align: 'center', title: '创建时间' },
                { align: 'center', width: 150, toolbar: '#tableBar', title: '操作' },
            ]]
        })
    })
</script>